// pages/order_detail/order_detail.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    o_detail:{},
    all_price:'',
  },
  repay: function (e) {
    var that = this
    var o_detail = this.data.o_detail
    var order_id = o_detail.order_id
    app.ajax({
      url: app.host + "mall/order/repay?order_id=" + order_id,
      success: function (res) {
        var parameters = res.data.data.parameters
        parameters.success = function () {
          wx.showToast({
            title: '支付成功',
          })
          o_detail.order_status = 20
          that.setData({
            o_detail: o_detail
          })
        }
        if (res.code == 0) {
          wx.showModal({
            title: '提示',
            content: res.data.msg,
            success: function (msg) {
              if (msg.confirm) {
                wx.requestPayment(parameters)
              }
            }
          })
        } else {
          wx.requestPayment(parameters)
        }
      }
    })
  },
  cancel: function (e) {
    var ispay = e.currentTarget.dataset.ispay
    var that = this
    var o_detail = this.data.o_detail
    if (ispay) {
      wx.showModal({
        title: '确定取消该订单吗？',
        success: function (res) {
          if(res.confirm){
            app.ajax({
              url: app.host + "mall/order/cancel?order_id=" + o_detail.order_id,
              success: function () {
                o_detail.order_status = 10
                that.setData({
                  o_detail: o_detail
                })
                wx.showToast({
                  title: '取消成功',
                })
              }
            })
          } 
        }
      })
    } else {
      wx.showModal({
        title: '取消订单',
        content: '取消订单请拨打客服电话，是否拨打？',
        success: function (res) {
          if (res.confirm) {
            wx.makePhoneCall({
              phoneNumber: '0871-63561965',
            })
          }
        }
      })
    }
  },
  finish:function(e){
    var that = this
    var order_id = e.currentTarget.dataset.order_id
    app.ajax({
      url:app.host + 'mall/order/finish?order_id=' + order_id,
      success:function(res){
        wx.showToast({
          title: '确认成功',
        })
        var o_detail = that.data.o_detail
        o_detail.order_status = 100
        that.setData({
          o_detail: o_detail
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var order_id = options.order_id
    wx.showLoading({
      title: '加载中',
    })
    app.ajax({
      url: app.host + "mall/order/orderdetail?order_id=" + order_id,
      success:function(res){
        wx.hideLoading()
        console.log(res.data.data)
        that.setData({
          o_detail:res.data.data,
          all_price: res.data.data.goods_money
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})